package com.ruoyi.web.controller.chen;/*
 *@author zw
 *date 2021/6/7 17:10
 *desc :
 */

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
public class chenController {
    
    @Value("${ruoyi.profile}")
    private String FileUplod;
    /**
     * 生成验证码
     */
    @GetMapping("/getimg")
    public AjaxResult getCode(HttpServletResponse response) throws IOException
    {
        List<String> filePathList = Lists.newArrayList();
         FileUtils.getFile(filePathList,FileUplod, 5);
        List filePathResult = Lists.newArrayList();
        filePathList.forEach(filePath->{

            String replace = filePath.replace("\\", "/").replace(FileUplod + "/upload", "");
            filePathResult.add("http://localhost:8080/img"+replace);
        });
        AjaxResult ajax = AjaxResult.success();
        ajax.put("imgPath",filePathResult);
        return ajax;
    }
}
